<?php
function bpsc_display_products_page( $query ) {
  global $wpdb, $wpsc_query, $wpsc_theme_path;
	
	/// added by xiligroup.dev to be compatible with touchshop
	$cur_wpsc_theme_folder = apply_filters('wpsc_theme_folder',$wpsc_theme_path.WPSC_THEME_DIR);
	/// end of added by xiligroup.dev to be compatible with touchshop
  
  $temp_wpsc_query = new BPSC_query($query);
  list($wpsc_query, $temp_wpsc_query) = array($temp_wpsc_query, $wpsc_query); // swap the wpsc_query objects
  
	$GLOBALS['nzshpcrt_activateshpcrt'] = true;
	ob_start();
	if(wpsc_is_single_product()) {
		include($cur_wpsc_theme_folder."/single_product.php");
	} else {
		// get the display type for the selected category
		if(is_numeric($wpsc_query->query_vars['category_id'])) {
			$category_id =(int) $wpsc_query->query_vars['category_id'];
			$display_type = $wpdb->get_var("SELECT `display_type` FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `id`='{$category_id}' LIMIT 1");
		}

		$display_type = 'list'; //DJPaul get_option('product_view');
		
		//exit($display_type);
		// switch the display type, based on the display type variable...
		switch($display_type) {
			case "grid":
			if(file_exists($cur_wpsc_theme_folder."/grid_view.php")) {
				include($cur_wpsc_theme_folder."/grid_view.php");
				break; // only break if we have the file;
			}
			
			case "list":
			if(file_exists($cur_wpsc_theme_folder."/list_view.php")) {
				include($cur_wpsc_theme_folder."/list_view.php");
				break; // only break if we have the file;
			}
			
			case "default":  // this may be redundant :D
				include($cur_wpsc_theme_folder."/products_page.php");
			break;
		}
	}
	$output = ob_get_contents();
	ob_end_clean();
	//$output = str_replace('$','\$', $output);

	list($temp_wpsc_query, $wpsc_query) = array($wpsc_query, $temp_wpsc_query); // swap the wpsc_query objects back
	return $output;
}

//Friend recommendations for http://example.com/profile/admin/store/
function bpsc_store_recommendations() {
	global $bp, $wpdb;

	$friends = array();
	if ( bp_has_members( 'type=alphabetical&populate_extras=false&user_id=' . $bp->loggedin_user->id ) )
		while ( bp_members() ) {
			bp_the_member();
			$friends[] = intval( bp_get_member_user_id() );
		}

	$product_ids = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT c.prodid FROM " . WPSC_TABLE_CART_CONTENTS . " as c, " . WPSC_TABLE_PURCHASE_LOGS . " as l WHERE c.purchaseid = l.id AND l.user_ID IN (%d)", implode( ', ', $friends ) ) );
	$product_ids = array(1,2);
	if ( $product_ids ) {
		echo bpsc_display_products_page( array( 'product_id' => $product_ids ) );

	} else { ?>
		<div id="message" class="info">
			<p><?php _e( 'Sorry, we have no recommendations for you. Check back soon!', 'bpsc' ) ?></p>
		</div>
	<?php
	}
}
?>